## zixue@taobao.com
## 2008-6-16

import urllib
from Log import Log

class HttpRsp():
	def __init__(self, statusCode=None, headers=None, content=None):
		self.statusCode=statusCode
		self.content=content
		self.headers = headers

class DefaultHttp():
	def get(self, url):
		result = urllib.urlopen(url)
		rsp = HttpRsp()
		rsp.content = result.read()
		return rsp

class HttpClient():
	def __init__(self, adapter=DefaultHttp()) :
		self.adapter = adapter

	def get(self, url):
		"""get(url) -> HttpResponse

		Do Http Get request and return HttpResponse

		"""
		#Log.debug("req url:" + url)
		rsp = self.adapter.get(url)
		Log.debug("http rsq\nstatusCode:" + str(rsp.statusCode) + "\ncontent:" + str(rsp.content))
		return rsp

def main():
	Log.enableDebug = True
	client = HttpClient()
	rsp = client.get('http://www.yahoo.com')
	Log.debug('html:\n' + rsp.content)
		
if __name__ == "__main__":
	main()